package com.jiangjiang.eshop.membership.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.membership.dao.UserAccountMapper;
import com.jiangjiang.eshop.membership.domain.UserAccountEntity;
import com.jiangjiang.eshop.membership.dto.PasswordUpdateDTO;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserAccountService
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/21 12:07
 * @Version 1.0
 **/
@Service
public class UserAccountService extends ServiceImpl<UserAccountMapper, UserAccountEntity> {

    /**
     * 根据手机号查询用户账户
     *
     * @param cellPhoneNumber 用户注册手机号
     * @return 查询结果
     */
    public UserAccountEntity queryByPhoneNumber(String cellPhoneNumber) {
        LambdaQueryWrapper<UserAccountEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserAccountEntity::getCellPhoneNumber, cellPhoneNumber);
        return this.getOne(wrapper);
    }

    /**
     * 更新密码
     * @param dto 参数
     * @return 处理结果
     */
    public Boolean updatePassword(PasswordUpdateDTO dto) {
        LambdaUpdateWrapper<UserAccountEntity> wrapper = Wrappers.lambdaUpdate();
        wrapper.eq(UserAccountEntity::getCellPhoneNumber, dto.getPhoneNumber())
                .set(UserAccountEntity::getPassword, dto.getPassword());
        return this.update(wrapper);
    }
}
